pub mod cache;
pub mod cfg;
pub mod file;
pub mod iter;
pub mod plc;
pub mod real;
pub mod util;

use super::{
    err, err_value, get_dir, get_file, it_dir, json, mod_dir, ok, throw_err, Base, Client, ECode,
    JsonFile, LockFile, MapSv, RNull, Resp, SvCache, VBase, VMap, Value, VecV,
};

pub async fn doit(
    data: Value,
    model: &str,
    cmd: &str,
    lock: &LockFile,
    cache: SvCache,
    real: SvCache,
    client: &Client,
) -> Resp {
    match model {
        "iter" => {
            let v = iter::Iter;
            v.do_cmd(&data, cmd, cache, client).await
        }
        "real" => {
            let v = real::Real;
            v.do_cmd(&data, cmd, real).await
        }
        "cache" => {
            let v = cache::CfgCache;
            v.do_cmd(&data, cmd, cache).await
        }
        "config" => {
            let v = cfg::Cfg;
            v.do_cmd(&data, cmd, lock, cache).await
        }
        _ => throw_err!(ECode::NoServe, "no work serve"),
    }
}

pub async fn do_get(model: &str, cmd: &str, cache: SvCache) -> Resp {
    match model {
        "iter" => {
            let v = iter::Iter;
            v.do_get(cmd, cache).await
        }
        _ => throw_err!(ECode::NoServe, "no work get serve"),
    }
}
